﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using RedPanda.MusicPlayer.Utils;

namespace RedPanda.MusicPlayer.DataModel
{
    /// <summary>
    /// 标示专辑的实体类
    /// </summary>
    [Serializable]
    public class Album
    {
        private string id;//用来唯一标示这张专辑的字符串;
        private string title;
        private string artist;
        private string year;
        private string gerne;
        private int trackNum;

        //专辑的封面地址，如果音乐文件本身包含图片则读出后保存
        //如果没有则从网络获得并且保存至本地;
        private string coverLocation;//本地缓存的专辑封面

        public Album()
        {
        }

        public Album(string title, string artist, string year, string gerne, int trackNum,byte[] imgBytes)
        {
            this.title = title;
            this.artist = artist;
            this.year = year;
            this.gerne = gerne;
            this.trackNum = trackNum;
            this.id = MusicPlayerUtils.GetAlbumId(title, artist);

            if (imgBytes == null || imgBytes.Length ==0)
            {
                this.coverLocation = string.Empty;
            }
            else
            {
                //保存图片到本地指定文件夹;
                this.coverLocation=CoverArt.SaveCover(id, imgBytes);
            }

        }

        #region Property
        public string Title
        {
            get{ return title;}
            set{ title= value;}
        }

        public string Artist
        {
              get{ return artist ;}
               set { artist = value; }
        }

        public string Year
        {
            get { return year; }
            set { year= value; }
        }

        public string Gerne
        {
            get { return gerne; }
            set { gerne = value; }
        }

        public string CoverLocation
        {
            get { return coverLocation; }
            set { coverLocation = value; }
        }
        public string ID
        {
            get
            {
                return id;
            }
            set
            {
                id = value;
            }
        }
        public int TrackNum
        {
            get { return trackNum; }
            set { trackNum = value; }
        }

        #endregion

        public override bool  Equals(object obj)
        {
            return (obj as Album).ID.Equals(this.id);
        }
    }
}
